﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CaseStudy.AdminPortal
{
    public partial class ItemShowing : System.Web.UI.UserControl
    {
        private CheckBox chkBox = new CheckBox();
        private Label lblTitle = new Label();
        private HyperLink lnkUrl = new HyperLink();

        public string Id
        {
            get { return chkBox.ID; }
            set 
            { 
                chkBox.ID = value;
                chkBox.Attributes.Add("FlagValue", value);
            }
        }

        public bool IsCheck
        {
            get { return chkBox.Checked; }
            set { chkBox.Checked = value; }
        }

        public bool IsEnable
        {
            get { return chkBox.Enabled; }
            set { chkBox.Enabled = value; }
        }

        public string CssClass
        {
            get { return chkBox.CssClass; }
            set { chkBox.CssClass = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public ItemShowing(bool cheched, bool isEnabled, string title, string urlNav)
        {
            lnkUrl.Target = "_blank";

            chkBox.Checked = cheched;
            chkBox.Enabled = isEnabled;
            chkBox.Attributes.Add("title", title);
            lblTitle.Text = title;
            lnkUrl.Text = urlNav;
            lnkUrl.NavigateUrl = urlNav;

            Panel pnlRelatedItem = new Panel();
            Table tblRelatedItem = new Table();

            TableRow row = new TableRow();
            TableCell cellLeft = new TableCell();
            TableCell cellMiddle = new TableCell();
            TableCell cellRight = new TableCell();
            cellLeft.Controls.Add(chkBox);
            cellMiddle.Controls.Add(lblTitle);

            row.Cells.Add(cellLeft);
            row.Cells.Add(cellMiddle);

            if (!string.IsNullOrEmpty(urlNav))
            {
                cellRight.Controls.Add(lnkUrl);
                row.Cells.Add(cellRight);
            }

            tblRelatedItem.Rows.Add(row);
            pnlRelatedItem.Controls.Add(tblRelatedItem);
            this.Controls.Add(pnlRelatedItem);

            pnlRelatedItem.CssClass = "ItemPanel";
            cellLeft.CssClass = "LeftCell";
            cellMiddle.CssClass = "MiddleCell";
            cellRight.CssClass = "RightCell";
            lblTitle.CssClass = "itemTitle";
            lnkUrl.CssClass = "itemUrl";
        }
    }
}